#include <iostream>
#include "contacts.pb.h"
int main()
{
    contacts::PersonInfo person;
    person.set_name("张三");
    person.set_age(20);
    std::string person_str;
    //序列化
    if(!person.SerializeToString(&person_str))
    {
        std::cerr<<"序列化失败";
        return -1;
    }
    std::cout<<"序列化成功，结果是:"<<std::endl;
    std::cout<<person_str<<std::endl;
    //反序列化
    contacts::PersonInfo person1;
    if(!person1.ParseFromString(person_str))
    {
        std::cerr<<"反序列化失败";
        return -2;
    }
    std::cout<<"反序列化成功"<<std::endl
             <<"name: "<<person1.name()<<std::endl
             <<"age: "<<person1.age()<<std::endl;
    return 0;
}